package com.yunhe.rentcars.pro.service.car.impl;

import com.yunhe.rentcars.commons.annoaction.Log;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.dao.car.CarsDao;
import com.yunhe.rentcars.pro.entity.rent.Cars;
import com.yunhe.rentcars.pro.service.car.CarsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author maliang
 * @version V1.0
 * @date 2017/11/27 0027 20:19
 * @Description: 车辆信息业务操作
 */
@Service
public class CarsServiceImpl implements CarsService {
    @Autowired
    private CarsDao carsDao;
    @Override
    public void save(Cars cars) {
        carsDao.save(cars);
    }

    @Override
    @Log(value = "删除车辆信息",type = 2)
    public void delBatch(String ids) {
        String[] split = ids.split(",");
        carsDao.delBatch(split);
    }

    @Override
    @Log(value = "修改车辆信息",type = 3)
    public void update(Cars cars) {
        carsDao.update(cars);
    }

    @Override
    public Pageable<Cars> findList(Cars cars, Integer offset, Integer limit) {
        Pageable<Cars> pageable = new Pageable<>();
        Long count = carsDao.findCount(cars);
        List<Cars> list = null;
        if(count > 1){
            list = carsDao.findList(cars.getCarcode(), cars.getCarstate(), offset, limit);
        }
        pageable.setTotal(count.intValue());
        pageable.setRows(list);
        return pageable;
    }

    @Override
    public Cars findOne(Long carid, String carcode) {
        return carsDao.findOne(carid,carcode);
    }

    @Override
    public void carState(Cars cars) {
        carsDao.carState(cars);
    }
}
